#※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
# File Name: install.sh
# Author: GID5564
# Description:安装完AidLux后，运行此文件
# Created Time: 03/10/22-07:56:32
#※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
#! /usr/bin/bash


function apt_install(){
    for pkg in "$@"
    do
        [[ -z $(command -v ${pkg}) ]] && {
            sudo apt install -y ${pkg}
        }
    done
    unset pkg
}

#start
#安装目录
export INSTALL_DIR="/root/.aidboot"
export FILE_RC='/root/.rc.local'
export GITEE='https://gitee.com/gid5564/aidtool.git'

printf "\033[34m %s \033[m\n" "更新源及软件包…"
#更新源与软件包
sudo apt update && apt -y upgrade
sudo apt --fix-broken install 
sudo apt_install git curl wget sudo gawk apt-transport-https

#-------------------
#awk版本可能有问题，列以执行:
#apt --fix-broken install 
#apt install -y gawk 

#解决错误: fatal: unable to access ‘https://github.com/...../‘: gnutls_handshake() failed: The TLS connection..
#sudo apt install -y apt-transport-https
#-------------------


#克隆脚本
printf "\033[34m %s \033[m\n" "克隆脚本…"
if [[ ! -e "${INSTALL_DIR}/.git" ]];then
    rm -rvf ${INSTALL_DIR} 2>/dev/null
    git clone ${GITEE} ${INSTALL_DIR}
else
    #git_pull_aidboot
    cd ${INSTALL_DIR}
	git reset --hard origin/master
	git pull --rebase --stat origin master --allow-unrelated-histories || git rebase --skip
	case "${?}" in
	0) ;;
	*)
		git fetch --depth=2
		git reset --hard
		git pull --rebase --stat --allow-unrelated-histories || git rebase --skip
		;;
	esac
	cd ${cur}
fi
printf "\033[34m %s \033[m\n" "配置.rc.local…"

#设置启动
[[ -s ${FILE_RC} ]] && {
    chmod +x ${FILE_RC}
    mv -f ${FILE_RC} "${FILE_RC}_bk"
} 
#config_boot
    cat >${FILE_RC} <<-'EOF'
:<<!
【脚本说明】
1、此脚本为配置文件.rc.local内容;
2、加载用于引导的函数;
3、启动引导程序;
4、请注意，您必须运行“chmod +x /root/.rc.local”以确保配置完后，须修改本脚本文件的权限;
5、此脚本将在引导过程中执行.
!
EOF
    #修改权限
    chmod +x ${FILE_RC} 
    echo "source ${INSTALL_DIR}/boot/boot.sh
    " >>${FILE_RC} 



printf "\033[1;35m %s\033[m\033[1;31m%s\033[m\033[1;35m%s \033[m\n" "正在准备重启aidlux,按" "回车键" "继续…"
read
aid-reboot #aidlux命令


































